let json2xml = require('pt-core-common').util.json2xml;
let feedsTemplate = require('./feeds.templates.func');

let feedsProductTemplate = {
    messageListTemplate: function(operationType, productList){
        let messageList = [];
        let index = 0;
        productList.forEach(product => {
            index++;
            messageList.push({
                MessageID: index,
                OperationType: operationType,
                Product: product
            })
        });
        return messageList;
    },
    amazonEnvelopeTemplate2xml: function(sellerId, operationType, productList){
        const messageList = feedsProductTemplate.messageListTemplate(operationType, productList);
        return json2xml("AmazonEnvelope", feedsTemplate.amazonEnvelopeTemplate(sellerId, "Product", messageList, {PurgeAndReplace: "false"}));
    }
};

module.exports = feedsProductTemplate;